//
//  OtherPersonView.m
//  Comma
//
//  Created by 杜远洋 on 15-1-30.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "OtherPersonView.h"
#import "PersonalCustomView.h"
#import "GlobalMethod.h"
#import "GlobalMacro.h"
#import "EditDetailViewController.h"
#import "AFNetWorkingYU.h"
#import "URLMacro.h"
#import "UIImageView+WebCache.h"

@implementation OtherPersonView


- (void)setInforDic:(NSDictionary *)InforDic
{
    _InforDic = InforDic;
    [self createMyPersonalCenter];
}
- (void)createMyPersonalCenter
{
    [self setBackgroundColor:[UIColor whiteColor]];
    [self createPersonalInformation];
    [self createMyFonderInfomation];
    [self createSchoolInformation];
    
}

- (void)createPersonalInformation
{
    self.myPhoto = [[UIButton alloc] initWithFrame:CGRectMake(16, 88, 80, 80)];
    self.myPhoto.layer.cornerRadius = 40;
    self.myPhoto.layer.masksToBounds = YES;
    NSString *url = [self.InforDic objectForKey:@"img"];
    NSString *strUrl = [NSString stringWithFormat:@"http://www.isu.so/attached/u_img/%@", url];
    //得到图像数据
    NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:strUrl]];
    [self.myPhoto setBackgroundImage:[UIImage imageWithData:imgData] forState:UIControlStateNormal];
    [self.myPhoto setBackgroundColor:[UIColor lightGrayColor]];
    [self addSubview:self.myPhoto];
    
    self.myName = [[UILabel alloc] initWithFrame:CGRectMake(16, 192, 80, 14)];
    [self.myName setBackgroundColor:[UIColor clearColor]];
    [self.myName setTextAlignment:NSTextAlignmentCenter];
    [self.myName setFont:[UIFont systemFontOfSize:14]];
    [self.myName setText:[self.InforDic objectForKey:@"nick"]];
    [self addSubview:self.myName];
    
    [self PersonalInformationSeperateLine];
    
}


- (void)createMyFonderInfomation
{
    self.profile = [[UILabel alloc] initWithFrame:CGRectMake(144, 105, 200, 50)];
    if (iPhone6Plus) {
        [self.profile setFrame:CGRectMake(144, 105, 250, 50)];
    }
    if (iPhone5) {
        [self.profile setFrame:CGRectMake(144, 95, 150, 65)];
    }

    [self.profile setBackgroundColor:[UIColor clearColor]];
    [self.profile setTextColor:BLACKCOLOR];
    [self.profile setFont:[UIFont systemFontOfSize:14]];
    [self.profile setNumberOfLines:0];
    [self.profile setText:[self.InforDic objectForKey:@"profile"]];
    [self addSubview:self.profile];
    
    UIImageView *goodPicture = [[UIImageView alloc] initWithFrame:CGRectMake(144, 192, 13, 18)];
    [goodPicture setImage:[UIImage imageNamed:@"Button_Praisesmall_effect"]];
    [goodPicture setBackgroundColor:[UIColor clearColor]];
    [self addSubview:goodPicture];
    
    
    UILabel *goodLabel = [[UILabel alloc] initWithFrame:CGRectMake(162, 192, 30, 15)];
    NSNumber *goodNumber = [self.InforDic objectForKey:@"good"];
    NSString *good = [NSString stringWithFormat:@"%@",goodNumber];
    [goodLabel setText:good];
    //    [goodLabel setText:@"1231"];
    [goodLabel setFont:[UIFont systemFontOfSize:11]];
    [goodLabel setBackgroundColor:[UIColor clearColor]];
    [self addSubview:goodLabel];
    
    
    UIImageView *badPicture = [[UIImageView alloc] initWithFrame:CGRectMake(211, 192, 13, 18)];
    [badPicture setImage:[UIImage imageNamed:@"Button_Belittlesmall"]];
    [badPicture setBackgroundColor:[UIColor clearColor]];
    [self addSubview:badPicture];
    
    UILabel *badLabel = [[UILabel alloc] initWithFrame:CGRectMake(229, 192, 30, 15)];
    NSNumber *badNumber = [self.InforDic objectForKey:@"bad"];
    NSString *bad = [NSString stringWithFormat:@"%@", badNumber];
    [badLabel setText:bad];
    [badLabel setFont:[UIFont systemFontOfSize:11]];
    [badLabel setBackgroundColor:[UIColor clearColor]];
    [self addSubview:badLabel];
    
}
- (void)createSchoolInformation
{
    //年龄与性别需要拼接字符串
    UIView *infoView = [[UIView alloc] initWithFrame:CGRectMake(16, 230, SCREEN_WIDTH - 16, 195)];
    [infoView setBackgroundColor:[UIColor clearColor]];
    [self addSubview:infoView];
    NSArray *titleArray = [NSArray arrayWithObjects:@"院校", @"入学年份", @"年龄与性别", @"专业", @"系别", nil];
    for (int i = 0; i < 5; i++) {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,  38 * i, SCREEN_WIDTH - 32, 15) ];
        [titleLabel setTextColor:TEXTGREENCOLOR];
        [titleLabel setText:[titleArray objectAtIndex:i]];
        [titleLabel setFont:[UIFont systemFontOfSize:11]];
        [titleLabel setBackgroundColor:[UIColor clearColor]];
        [infoView addSubview:titleLabel];
    }
    
    //学校
    self.school = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, SCREEN_WIDTH - 32, 20)];
    [self.school setTextColor:BLACKCOLOR];
    [self.school setFont:[UIFont systemFontOfSize:14]];
    [self.school setBackgroundColor:[UIColor clearColor]];
    [self.school setText:[self.InforDic objectForKey:@"school"]];
    [infoView addSubview:_school];
    
    //年级（入学年）
    self.grade = [[UILabel alloc] initWithFrame:CGRectMake(0, 53, SCREEN_WIDTH - 32, 20)];
    [self.grade setTextColor:BLACKCOLOR];
    [self.grade setFont:[UIFont systemFontOfSize:14]];
    [self.grade setBackgroundColor:[UIColor clearColor]];
    [self.grade setText:[self.InforDic objectForKey:@"grade"]];
    [infoView addSubview:_grade];
    
    //年龄和性别
    self.ageAndSex = [[UILabel alloc] initWithFrame:CGRectMake(0, 91, SCREEN_WIDTH - 32, 20)];
    [self.ageAndSex setTextColor:BLACKCOLOR];
    [self.ageAndSex setFont:[UIFont systemFontOfSize:14]];
    [self.ageAndSex setBackgroundColor:[UIColor clearColor]];
    //不知道年龄是什么类型的  暂且算是字符串
    [self.ageAndSex setText:[self getMyAgeAndSex]];
    [infoView addSubview:_ageAndSex];
    
    //专业
    self.major = [[UILabel alloc] initWithFrame:CGRectMake(0, 129, SCREEN_WIDTH - 32, 20)];
    [self.major setTextColor:BLACKCOLOR];
    [self.major setFont:[UIFont systemFontOfSize:14]];
    [self.major setBackgroundColor:[UIColor clearColor]];
    [self.major setText:[self.InforDic objectForKey:@"major"]];
    [infoView addSubview:_major];
    
    //系别
    self.dept = [[UILabel alloc] initWithFrame:CGRectMake(0, 167, SCREEN_WIDTH - 32, 20)];
    [self.dept setTextColor:BLACKCOLOR];
    [self.dept setBackgroundColor:[UIColor clearColor]];
    [self.dept setFont:[UIFont systemFontOfSize:14]];
    [self.dept setText:[self.InforDic objectForKey:@"dept"]];
    [infoView addSubview:_dept];
    
    
}
- (void)PersonalInformationSeperateLine
{
    [GlobalMethod drawLineWithStartPoint:CGPointMake(16, 425) EndPoint:CGPointMake(SCREEN_WIDTH, 425) inUIView:self];
}

- (void)myDynamicSeperateLine
{
    [GlobalMethod drawLineWithStartPoint:CGPointMake(16, 469) EndPoint:CGPointMake(SCREEN_WIDTH, 469) inUIView:self];
}

- (NSString *)getMyAgeAndSex
{
    NSNumber *myAge = [self.InforDic objectForKey:@"age"];
    NSString *gender = [self.InforDic objectForKey:@"gender"];
    NSString *age = [NSString stringWithFormat:@"%@",myAge];
    if (age.length == 0 && gender.length != 0) {
        NSString *ageAndGender = [NSString stringWithFormat:@"    %@", gender];
        return ageAndGender;
    }
    else if ( gender.length == 0 && age.length != 0) {
        NSString *ageAndGender = [NSString stringWithFormat:@"%@   ", age];
        return ageAndGender;
    }
    else if ( age.length == 0 && gender.length == 0)
    {
        
        return nil;
    }
    else
    {
        NSString *ageAndGender = [NSString stringWithFormat:@"%@ %@", age, gender];
        return ageAndGender;
    }
    
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self endEditing:YES];
}












@end
